package com.luci.security.result;

import java.io.Serializable;
import java.util.List;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 *
 *
 * @author yuyanan01@beyondsoft.com
 * @version 1.0
 * @date 18-10-30
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class JwtUser {

    /**
     * 角色集合
     */
    private List<String> roles;

    /**
     * 用户信息
     */
    private Object details;

    public static JwtUser getLoginUser() {
        String detail = (String) SecurityContextHolder.getContext().getAuthentication().getDetails();
        if (detail == null) {
            return null;
        }
        return JSON.parseObject(detail, JwtUser.class);
    }

}
